package com.sub.project.mall.contorller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.sub.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sub.framework.aspectj.lang.annotation.Log;
import com.sub.framework.aspectj.lang.enums.BusinessType;
import com.sub.project.mall.domain.OmsOrderItem;
import com.sub.project.mall.service.IOmsOrderItemService;
import com.sub.framework.web.controller.BaseController;
import com.sub.framework.web.domain.AjaxResult;
import com.sub.common.utils.poi.ExcelUtil;
import com.sub.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 *
 * @author sub
 * @date 2020-08-23
 */
@RestController
@RequestMapping("/mall/item" )
public class OmsOrderItemController extends BaseController {
    @Autowired
    private IOmsOrderItemService omsOrderItemService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('mall:item:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(OmsOrderItem omsOrderItem) {
        startPage();
        QueryWrapper<OmsOrderItem> queryWrapper = new QueryWrapper<OmsOrderItem>();
if(omsOrderItem.getOrderId() != null){
     queryWrapper.eq("order_id" ,omsOrderItem.getOrderId());
}
    if(StringUtils.isNotBlank(omsOrderItem.getOrderSn())){
     queryWrapper.eq("order_sn" ,omsOrderItem.getOrderSn());
}
    if(omsOrderItem.getProductId() != null){
     queryWrapper.eq("product_id" ,omsOrderItem.getProductId());
}
    if(StringUtils.isNotBlank(omsOrderItem.getProductPic())){
     queryWrapper.eq("product_pic" ,omsOrderItem.getProductPic());
}
                        if (StringUtils.isNotBlank(omsOrderItem.getProductName())){
            queryWrapper.like("product_name" ,omsOrderItem.getProductName());
        }
            if(StringUtils.isNotBlank(omsOrderItem.getProductBrand())){
     queryWrapper.eq("product_brand" ,omsOrderItem.getProductBrand());
}
    if(StringUtils.isNotBlank(omsOrderItem.getProductSn())){
     queryWrapper.eq("product_sn" ,omsOrderItem.getProductSn());
}
    if(omsOrderItem.getProductPrice() != null){
     queryWrapper.eq("product_price" ,omsOrderItem.getProductPrice());
}
    if(omsOrderItem.getProductQuantity() != null){
     queryWrapper.eq("product_quantity" ,omsOrderItem.getProductQuantity());
}
    if(omsOrderItem.getProductSkuId() != null){
     queryWrapper.eq("product_sku_id" ,omsOrderItem.getProductSkuId());
}
    if(StringUtils.isNotBlank(omsOrderItem.getProductSkuCode())){
     queryWrapper.eq("product_sku_code" ,omsOrderItem.getProductSkuCode());
}
    if(omsOrderItem.getProductCategoryId() != null){
     queryWrapper.eq("product_category_id" ,omsOrderItem.getProductCategoryId());
}
    if(StringUtils.isNotBlank(omsOrderItem.getSp1())){
     queryWrapper.eq("sp1" ,omsOrderItem.getSp1());
}
    if(StringUtils.isNotBlank(omsOrderItem.getSp2())){
     queryWrapper.eq("sp2" ,omsOrderItem.getSp2());
}
    if(StringUtils.isNotBlank(omsOrderItem.getSp3())){
     queryWrapper.eq("sp3" ,omsOrderItem.getSp3());
}
                        if (StringUtils.isNotBlank(omsOrderItem.getPromotionName())){
            queryWrapper.like("promotion_name" ,omsOrderItem.getPromotionName());
        }
            if(omsOrderItem.getPromotionAmount() != null){
     queryWrapper.eq("promotion_amount" ,omsOrderItem.getPromotionAmount());
}
    if(omsOrderItem.getCouponAmount() != null){
     queryWrapper.eq("coupon_amount" ,omsOrderItem.getCouponAmount());
}
    if(omsOrderItem.getIntegrationAmount() != null){
     queryWrapper.eq("integration_amount" ,omsOrderItem.getIntegrationAmount());
}
    if(omsOrderItem.getRealAmount() != null){
     queryWrapper.eq("real_amount" ,omsOrderItem.getRealAmount());
}
    if(omsOrderItem.getGiftIntegration() != null){
     queryWrapper.eq("gift_integration" ,omsOrderItem.getGiftIntegration());
}
    if(omsOrderItem.getGiftGrowth() != null){
     queryWrapper.eq("gift_growth" ,omsOrderItem.getGiftGrowth());
}
    if(StringUtils.isNotBlank(omsOrderItem.getProductAttr())){
     queryWrapper.eq("product_attr" ,omsOrderItem.getProductAttr());
}
            List<OmsOrderItem> list = omsOrderItemService.list(queryWrapper);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize("@ss.hasPermi('mall:item:export')" )
    @Log(title = "【请填写功能名称】" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(OmsOrderItem omsOrderItem) {
        QueryWrapper<OmsOrderItem> queryWrapper = new QueryWrapper<OmsOrderItem>(omsOrderItem);
        List<OmsOrderItem> list = omsOrderItemService.list(queryWrapper);
        ExcelUtil<OmsOrderItem> util = new ExcelUtil<OmsOrderItem>(OmsOrderItem. class);
        return util.exportExcel(list, "item" );
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize("@ss.hasPermi('mall:item:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(omsOrderItemService.getById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('mall:item:add')" )
    @Log(title = "【请填写功能名称】" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsOrderItem omsOrderItem) {
        return toAjax(omsOrderItemService.save(omsOrderItem) ? 1 : 0);
    }

    /**
     * 修改【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('mall:item:edit')" )
    @Log(title = "【请填写功能名称】" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsOrderItem omsOrderItem) {
        return toAjax(omsOrderItemService.updateById(omsOrderItem) ? 1 : 0);
    }

    /**
     * 删除【请填写功能名称】
     */
    @PreAuthorize("@ss.hasPermi('mall:item:remove')" )
    @Log(title = "【请填写功能名称】" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(omsOrderItemService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
